package calculette;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class Calculette extends JFrame
{
	private JLabel affichage;
	private JButton buttonCE, buttonDEL, buttonMR, buttonMP, buttonMM, button7, button8;
	private JButton button9, buttonDiv, button4, button5, button6, buttonMul, button1;
	private JButton button2, button3, buttonMoin, button0, buttonPoint, buttonEgual, buttonPlus;
	private JTextField hitorique;
	
	public Calculette()
	{
		super("Calculette");
		
		setFont(new Font("Arial", Font.BOLD, 16));
		
		setContentPane(buildContent());

		pack();
		setVisible(true);
	}
	
	private JPanel buildContent()
	{
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		panel.add(buildInterface(), BorderLayout.WEST);
		panel.add(buildHistorique(), BorderLayout.CENTER);
		
		return panel;
	}
	
	private JPanel buildInterface()
	{
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		panel.add(buildPrompt(), BorderLayout.NORTH);
		panel.add(buildPavNum(), BorderLayout.CENTER);
		
		return panel;
	}
	
	private JPanel buildPrompt()
	{
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		//Création des boutons du prompteur
		JPanel buttonContainer = new JPanel();
		buttonContainer.setLayout(new BoxLayout(buttonContainer, BoxLayout.X_AXIS));
		
		buttonCE = new JButton("CE");
		buttonCE.setBackground(Color.red);
		buttonCE.setForeground(Color.white);
		
		buttonDEL = new JButton("DEL");
		buttonDEL.setBackground(Color.red);
		buttonDEL.setForeground(Color.white);
		
		buttonContainer.add(buttonCE);
		buttonContainer.add(buttonDEL);
		
		//Création de l'affichage de text
		affichage = new JLabel();
		
		//Ajout des éléments au panel
		panel.add(buttonContainer, BorderLayout.WEST);
		panel.add(buttonContainer, BorderLayout.CENTER);
		return panel;
	}
	
	private JPanel buildPavNum()
	{
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(5,4));
		
		//Création des boutons
		buttonCE = new JButton("MC");
		buttonCE.setBackground(Color.blue);
		
		buttonMR = new JButton("MR");
		buttonMP = new JButton("M+");
		buttonMM = new JButton("M-");
		button7 = new JButton("7");
		button8 = new JButton("8");
		button9 = new JButton("9");
		buttonDiv = new JButton("/");
		button4 = new JButton("4");
		button5 = new JButton("5");
		button6 = new JButton("6");
		buttonMul = new JButton("x");
		button1 = new JButton("1");
		button2 = new JButton("2");
		button3 = new JButton("3");
		buttonMoin = new JButton("-");
		button0 = new JButton("0");
		buttonPoint = new JButton(".");
		buttonEgual = new JButton("=");
		buttonPlus = new JButton("+");
		
		// Ajout dans le panel
		panel.add(buttonCE);
		panel.add(buttonMR);
		panel.add(buttonMP);
		panel.add(buttonMM);
		panel.add(button7);
		panel.add(button8);
		panel.add(button9);
		panel.add(buttonDiv);
		panel.add(button4);
		panel.add(button5);
		panel.add(button6);
		panel.add(buttonMul);
		panel.add(button1);
		panel.add(button2);
		panel.add(button3);
		panel.add(buttonMoin);
		panel.add(button0);
		panel.add(buttonPoint);
		panel.add(buttonEgual);
		panel.add(buttonPlus);
		
		return panel;
	}
	
	private JTextField buildHistorique()
	{
		return hitorique = new JTextField();
	}
}
